//此文件为全局文件，请不要随意更改
// ajax请求请使用下面的格式
var url='http://120.24.42.44:8888';

function signin(){
    var skipURL=null;
    localStorage.url=url;
    var type=$('#form [name=type]').val();
    if(type=='0'){
         skipURL='adminHome.html';
    }
    else if(type=='1'){
        skipURL='hostsHome.html';
    }
    else
    {
        skipURL='devHome.html';
    }
    var obj = $('#form').serialize();//表单序列化
   // window.location.href='hostsHome.html';
    $.ajax({
        type: "post",//请求方式,post\get只要在这里改，其他地方不要改
        url: url+"/boss/base/login",//访问的地址
        data: obj,// 要提交的数据,
        dataType:'json',//传入数据的格式，可以统一用json
        success: function (msg) {
            if(msg.status=='ok!'){
                console.log(msg.msg);
                localStorage.id=msg.msg.id;
                localStorage.type=type;
                window.location.href=skipURL;
            }
            else{
                alert(msg.msg);
            }

        },
        error: function (error) {
            console.log('登录出错！');
        }
    });
}

function signUp() {
    var fields=$(':input').serializeArray();
    var flag=1;
    console.log(fields);
    $.each(fields,function(index,element){
       if(element.value==""){
           alert(element.name+"不能位空！");
           flag=0;
           return false;
       }
    });
    if(flag==1){
        var obj = $('#signupForm').serialize();

        $.ajax({
            type: "post",
            url: url+'/boss/base/signup',
            data: obj,// 要提交的表单
            dataType: "json",
            success: function (msg) {
                console.log(msg);
                if(msg.status=='ok!'){
                    alert('注册成功！')
                    window.location.href='index.html';
                }
                else{
                    alert(msg.msg);
                }
            },
            error: function (error) {
                alert('注册请求失败！'+error);
            }
        });
    }

}
